//
//  YWAssignMemberListTableViewController.m
//  maintain
//
//  Created by Kyo on 15/12/19.
//  Copyright © 2015年 ewin. All rights reserved.
//

#import "YWAssignMemberListTableViewController.h"
#import "YWHandler.h"

@interface YWAssignMemberListTableViewController (){
    NSInteger currentHandlerId;
}

@end

@implementation YWAssignMemberListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_handlers count];
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    
    static NSString* CellIdentifier = @"YWAssignMemberListTableViewControllerCellIdentifier";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    YWHandler *handler = [_handlers objectAtIndex:indexPath.row];
    cell.textLabel.text = handler.userName;
    
    cell.accessoryType = UITableViewCellAccessoryNone;
    if (currentHandlerId==handler.uniqueId) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    return cell;
}
#pragma mark Table view delegate

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return 40;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    YWHandler *handler = [_handlers objectAtIndex:indexPath.row];
    currentHandlerId = handler.uniqueId;
    [tableView reloadData];
    if ([_delegate respondsToSelector:@selector(selectHandler:)]) {
        [_delegate selectHandler:handler];
    }
}


@end
